<template>
	<div>
		<el-row :gutter="20">
			<el-col :span="24">
				<el-card shadow="hover">
					<template #header>
						<div class="clearfix">
							<span>个人中心</span>
						</div>
					</template>
					<el-form label-width="120px">
						<el-form-item label="账号(手机号码)："> {{ currentUserPhone }} </el-form-item>
						<el-form-item label="姓名：">
							<el-input v-model="form.name" style="width: 300px"></el-input>
						</el-form-item>
						<el-form-item label="账号类型："> {{ currentUserRole }} </el-form-item>
						<el-form-item label="注册时间："> {{ currentUserCreateTime }} </el-form-item>
						<el-form-item>
							<el-button type="primary" @click="onSubmit">保存</el-button>
						</el-form-item>
					</el-form>
				</el-card>
			</el-col>
		</el-row>
	</div>
</template>

<script setup lang="ts" name="user">
import { reactive, ref } from 'vue';
import VueCropper from 'vue-cropperjs';
import 'cropperjs/dist/cropper.css';
import avatar from '../assets/img/img.jpg';
import {ElMessage} from "element-plus";
import {updateWebUserApi} from "../api/index";

const currentUserId = localStorage.getItem('userId');
const currentUserName = localStorage.getItem('name');
const currentUserRole = localStorage.getItem('roleName');
const currentUserCreateTime = localStorage.getItem('createTime');
const currentUserPhone = localStorage.getItem('phone');
const buttonDisabled = ref(false);
const form = reactive({
	name: ''
});
form.name = currentUserName;
const onSubmit = async () => {
	buttonDisabled.value = true;
	if (!form.name) {
		ElMessage.warning("姓名不能为空")
		return;
	}
	const res = await updateWebUserApi({
		id: currentUserId,
		name: form.name
	});
	if (res) {
		ElMessage.success("保存成功");
		localStorage.setItem("name", form.name);
	}
	buttonDisabled.value = false;
};

</script>

<style scoped>
.info {
	text-align: center;
	padding: 35px 0;
}
.info-image {
	position: relative;
	margin: auto;
	width: 100px;
	height: 100px;
	background: #f8f8f8;
	border: 1px solid #eee;
	border-radius: 50px;
	overflow: hidden;
}

.info-edit {
	display: flex;
	justify-content: center;
	align-items: center;
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.5);
	opacity: 0;
	transition: opacity 0.3s ease;
}
.info-edit i {
	color: #eee;
	font-size: 25px;
}
.info-image:hover .info-edit {
	opacity: 1;
}
.info-name {
	margin: 15px 0 10px;
	font-size: 24px;
	font-weight: 500;
	color: #262626;
}
.crop-demo-btn {
	position: relative;
}
.crop-input {
	position: absolute;
	width: 100px;
	height: 40px;
	left: 0;
	top: 0;
	opacity: 0;
	cursor: pointer;
}
</style>
